package com.pifuke.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import cn.o.app.adapter.IItemView;
import cn.o.app.adapter.OAdapter;
import cn.o.app.adapter.OItemView;
import cn.o.app.ui.OImageView;
import cn.skinapp.R;

import com.lidroid.xutils.BitmapUtils;
import com.smiier.skin.net.DoctorReserveListTask.DoctorReserveItem;
import com.smiier.skin.utils.CommonUtility;

public class TreatmentMyProjectListAdapter extends OAdapter<DoctorReserveItem> {
	protected BitmapUtils mBitmapUtils;

	@Override
	protected void onContainerChanged() {
		mBitmapUtils = new BitmapUtils(getContext());
	}

	@Override
	public IItemView<DoctorReserveItem> getItemView() {
		return new TreatmentProjectItemView(getContext());
	}

	class TreatmentProjectItemView extends OItemView<DoctorReserveItem> {

		public TreatmentProjectItemView(Context context) {
			super(context);
		}

		private OImageView mImage;
		private TextView mTreatmentName;
		private TextView mHospitalName;
		private TextView mStatus;
		private TextView mTreatmentPrice;
		TextView mLevel;

		@Override
		public void onCreate() {
			setContentView(R.layout.treatment_item_my);
			mImage = findViewById(R.id.img_treatment, OImageView.class);
			mTreatmentName = findViewById(R.id.treatment_name, TextView.class);
			mHospitalName = findViewById(R.id.treatment_hospital,
					TextView.class);
			mLevel = findViewById(R.id.treatment_hospital_level, TextView.class);
			mStatus = findViewById(R.id.treatment_status, TextView.class);
			mTreatmentPrice = findViewById(R.id.treatment_price, TextView.class);
		}

		@Override
		public void onResume() {
			mTreatmentName.setText(mDataProvider.name);
			mHospitalName.setText(mDataProvider.hospital);
			// mHospitalLevel.setText(mDataProvider.);
			if (mDataProvider.url != null
					&& !mDataProvider.url.trim().equals("")) {
				mBitmapUtils.display(mImage, mDataProvider.url);
			}
			boolean hasName = CommonUtility.setHosLevel(mDataProvider.hospital,
					mLevel);
			if (!hasName) {
				mLevel.setVisibility(View.GONE);
			}
			mStatus.setText(mDataProvider.status);
			if (mDataProvider.status.equals("待确认")) {
				mStatus.setTextColor(Color.parseColor("#F6B64D"));
			} else if (mDataProvider.status.equals("已确认")) {
				mStatus.setTextColor(Color.parseColor("#70A1E4"));
			} else if (mDataProvider.status.equals("已消费")) {
				mStatus.setTextColor(Color.parseColor("#4ACE2F"));
			}
			if (mDataProvider.discount_price <= 0) {
				mTreatmentPrice.setText("具体价格请咨询医院");
			} else {
				mTreatmentPrice.setText("￥" + mDataProvider.discount_price);
			}
		}

	}
}
